package cn.doitedu.flink.suanzi;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

class Bean{
    String host;
    int port;
    String protocol;
    String method;
    HashMap<String,String> params = new HashMap<>();

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public HashMap<String, String> getParams() {
        return params;
    }

    public void setParams(HashMap<String, String> params) {
        this.params = params;
    }


    @Override
    public String toString() {
        return "Bean{" +
                "host='" + host + '\'' +
                ", port=" + port +
                ", protocol='" + protocol + '\'' +
                ", method='" + method + '\'' +
                ", params=" + params +
                '}';
    }
}
public class Url {

    public static void main(String[] args) throws MalformedURLException {
        Bean bean = new Bean();

        String url = "http://www.baidu.com/?method?key1=value1&key2=value2";
        URL u = new URL(url);
        bean.setPort(u.getPort());
        bean.setHost(u.getHost());
        bean.setProtocol(u.getProtocol());
        String query = u.getQuery();
        String[] split = query.split("\\?")[1].split("\\&");
        for (String s : split) {
            String[] kv = s.split("=");
            bean.getParams().put(kv[0],kv[1]);
        }

        System.out.println(bean);
    }
}
